import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


public class bullet extends Actor
{
    boolean exploding=false;
    int explode=0,a=1;
    GreenfootImage buffer = new GreenfootImage(5,5);

    
    public bullet(boolean dir){
        if(!dir)a=-1;
        setImage(buffer);
    }
    
    

    public void act() 
    {
      buffer.clear();
      if(exploding){
          explode++;
          if(explode==10){
              ((it) getWorld()).removeObject(this);
              return;
            }
          buffer.drawImage(((it)getWorld()).getBullet(),-(int)(explode/2)*5,0);
          if(a==-1)buffer.mirrorHorizontally();
          return;
        }
        
      buffer.drawLine(2,2,2,2);  
      setLocation(getX()+a*8,getY());
      if(!((it) getWorld()).ok(getX(),getY()) || getX()==599){
          exploding=true;
          while(!((it) getWorld()).ok(getX(),getY())){
              setLocation(getX()-1*a,getY());
            }
           setLocation(getX()-2*a,getY());
        }
      Enemy it1 = (Enemy) getOneIntersectingObject(Enemy.class);
        if(it1!=null){
            it1.hurt(2);
            getWorld().removeObject(this);
        }    
          
          
    }    
    
    
}
